package cqrtplm.controller;

import com.ty.basic.response.ResponseResult;
import cqrtplm.common.CommonService;
import cqrtplm.constant.RouteConstant;
import cqrtplm.dto.ExportToolDTO;
import cqrtplm.dto.ImportProcessStepDTO;
import cqrtplm.dto.KeyValueDTO;
import cqrtplm.service.RTCrmIntegrityService;
import cqrtplm.service.RTProcessRouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigInteger;
import java.util.List;

@RestController
@Api(tags = "工艺路线")
@RequestMapping(RouteConstant.PROCESS + "v1")
public class RTProcessRouteController {

    @Resource
    private RTProcessRouteService processRouteService;
    @Resource
    private RTCrmIntegrityService crmIntegrityService;
    @Resource
    private CommonService commonService;

    @PostMapping("/importProcessRoute")
    @ApiOperation(value = "importProcessRoute",notes = "工艺批量导入")
    @ResponseBody
    public ResponseResult importProcess(@ModelAttribute ImportProcessStepDTO dto) throws Exception {
        processRouteService.importProcess(dto);
        return ResponseResult.success();
    }

    @PostMapping("/exportToolsAndEquipment")
    @ApiOperation(value = "exportToolsAndEquipment",notes = "导出工装工具清单")
    @ResponseBody
    public void exportToolsAndEquipment(@RequestBody ExportToolDTO dto, HttpServletResponse response) throws Exception {
        processRouteService.exportToolsAndEquipment(dto, response);
    }

    @GetMapping("/getDevelopmentOrderList")
    @ApiOperation(value = "getDevelopmentOrderList",notes = "获取开发令集合")
    @ResponseBody
    public ResponseResult<List<KeyValueDTO>> getDevelopmentOrderList(String keword) throws Exception {
        return ResponseResult.success(processRouteService.getDevelopmentOrderList(keword));
    }

    @PostMapping("/download")
    public void download() throws Exception {
        commonService.downloadFileToFtp(new BigInteger("715578312581578756"), "/drawing/20250723/WT202507220008/");
    }

    @GetMapping("/getClientCodeList")
    public ResponseResult<List<KeyValueDTO>> getClientCodeList(@Param("clientName") String clientName) throws Exception {
        return ResponseResult.success(crmIntegrityService.getClientCodeList(clientName));
    }
}
